package tools.old.files;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.AbstractListModel;
import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;

import prototyping.client.teacher.model.TeacherClient;

import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;

import account.model.SubTeam;
import account.model.HelpListModel;

import com.sun.mail.handlers.message_rfc822;

import dao.server.DataLoadIP;

public class TeacherFrameExt extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L; 

	private String userName;
	private JLabel lblServing = new JLabel();
	private JList<HelpListModel> lstHelp = new JList<HelpListModel>();
	private JScrollPane srpHelp = new JScrollPane();
	private JButton btnNewButton = new JButton("Afhandelen");
	private HelpListModel hlm = new HelpListModel();

	DataLoadIP ip = new DataLoadIP();

	public TeacherFrameExt(String userName) {
		super(userName);
//		this.userName = SubTeam.getInstance().getAcc().getVoornaam();

		//Server IP automatisch bijwerken bij docenten
		ip.openConn();

		TeacherClient tc = new TeacherClient(ip.LoadServerIP(), userName);
		tc.addObserver(hlm);
		tc.start();

		initComponents();
	}

	private void initComponents() {
		
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setTitle("Hallo " + userName);
		setVisible(true);
		setResizable(false);
		pack();
		setSize(560, 321);

		Dimension center = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(center.width / 2 - this.getSize().width / 2,
				center.height / 2 - this.getSize().height / 2);
		
		
		lstHelp.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		lstHelp.setVisibleRowCount(5);
		lstHelp.getAccessibleContext().setAccessibleName("");
		lstHelp.setModel(hlm);

		srpHelp.setViewportView(lstHelp);

		lblServing.setText("Now serving...");

//		btnNewButton.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				if (hlm.getSize() > 0)
//					hlm.removeElementAt(0);
//			}
//		});

		GroupLayout layout = new GroupLayout(getContentPane());
		layout.setHorizontalGroup(
				layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(layout.createParallelGroup(Alignment.LEADING)
								.addGroup(layout.createSequentialGroup()
										.addGroup(layout.createParallelGroup(Alignment.LEADING)
												.addGroup(layout.createSequentialGroup()
														.addComponent(lblServing, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
														.addGap(310))
														.addComponent(srpHelp, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
														.addContainerGap())
														.addComponent(btnNewButton, Alignment.TRAILING)))
				);
		layout.setVerticalGroup(
				layout.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(lblServing)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(srpHelp, GroupLayout.PREFERRED_SIZE, 160, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(btnNewButton)
						.addContainerGap())
				);
		getContentPane().setLayout(layout);
		
	}

}
